from datetime import datetime

from dataAnalysis.data.utils import DButil as db
from dataAnalysis.data.utils.savedata import save_type

cursor= db.connection.cursor()
if __name__ == '__main__':
    sql = 'SELECT * FROM movies ORDER BY douban_id DESC'
    cursor.execute(sql)
    movie =cursor.fetchall()
    list_=[]
    for e in movie:
        listSplit=e['genres'].split("/")
        for s in listSplit:
            list_.append(s)

    unique_list = list(set(list_))
    for i, unique in enumerate(unique_list):
        type={}
        if unique:
            type.update({"id":i-1})
            type.update({"name":unique})
            type.update({"create_time":datetime.now().strftime('%Y-%m-%d %H:%M:%S')})
            type.update({"update_time":datetime.now().strftime('%Y-%m-%d %H:%M:%S')})
            type.update({"is_deleted":0})
            print(save_type(type))


